<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @abstract token
 * @author zxj
 */
class oauthService extends CI_Controller
{
    private $request;

    function __construct()
    {
        parent::__construct();
        $this->request = gp();
        if ($this->request) {
            log_output($this->request);
        }
        //登录验证
        //$this->userVerify($this->request['user'], $this->request['pwd']);
    }


    /**
     * 生成token
     */
    function get_access_token(){
        $token = 'zlj;123456'.time();
        $token = md5(md5($token));
        gsh_output($token);
    }


    /**
     * 验证是否登录
     * @param string $username 用户名
     * @param string $pwd 密码
     * @return mixed
     */
    function userVerify($username = '', $pwd = '')
    {
        //输出数据结构
        $where = array('account' => $username, 'password' => md5($pwd));
        if (!$username || !$pwd) {
            json_output($this->request, 'Invalid account password', false);
        } else {
            $users = $this->common_model->selectFirst('user', $where);
            if (!$users) {
                json_output(array('userData' => $users,
                    'username' => $username, 'pwd' => $pwd), 'Account or password error', false);
            }
        }
        return $users;
    }


}
